package cn.south.campus.business.model.vo;

import cn.south.campus.business.model.entity.Ad;
import cn.south.campus.common.model.vo.BaseVO;
import cn.south.campus.common.utils.DateUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 *
 * </p>
 *
 * @author chow
 * @since 2024/11/11 10:13
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class AdVo extends BaseVO {
    /**
     * 广告位posNo
     */
    private String posNo;

    /**
     * 广告位名称
     */
    private String positionName;

    /**
     * 标题
     */
    private String title;

    /**
     * 内容
     */
    private String content;

    /**
     * 图片
     */
    private String pic;
    /**
     * 链接
     */
    private String url;

    /**
     * 开始时间
     */
    private String startTime;

    /**
     * 结束时间
     */
    private String endTime;

    public static AdVo convert(Ad ad) {
        if (ad == null) {
            return null;
        }
        AdVo adVo = new AdVo();
        adVo.setId(ad.getId());
        adVo.setPosNo(ad.getPosNo());
        adVo.setPositionName(ad.getPositionName());
        adVo.setTitle(ad.getTitle());
        adVo.setContent(ad.getContent());
        adVo.setUrl(ad.getUrl());
        adVo.setPic(ad.getPic());
        adVo.setStartTime(DateUtil.format(ad.getStartTime()));
        adVo.setEndTime(DateUtil.format(ad.getEndTime()));
        return adVo;
    }

    public static Ad convert(AdVo adVo) {
        if (adVo == null) {
            return null;
        }
        Ad ad = new Ad();
        ad.setId(adVo.getId());
        ad.setPosNo(adVo.getPosNo());
        ad.setPositionName(adVo.getPositionName());
        ad.setTitle(adVo.getTitle());
        ad.setContent(adVo.getContent());
        ad.setUrl(adVo.getUrl());
        ad.setPic(adVo.getPic());
        ad.setStartTime(DateUtil.parseString(adVo.getStartTime()));
        ad.setEndTime(DateUtil.parseString(adVo.getEndTime()));
        return ad;
    }
}
